package ran.controller.sysuser;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import ran.constants.HttpConstants;
import ran.controller.BaseController;
import ran.domain.sysuser.dto.SysUserSaveDTO;
import ran.domain.sysuser.dto.LoginDTO;
import ran.entity.Result;
import ran.domain.sysuser.vo.SysUserVO;
import ran.service.sysuser.ISysUserService;
import ran.vo.LoginUserVO;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: ran
 * Date: 2025-10-03
 * Time: 14:41
 */
@RestController
@RequestMapping("/sysUser")
@Tag(name = "管理员API")
public class SysUserController extends BaseController {
    @Autowired
    private ISysUserService sysUserService;
    // 登录
    @Operation(summary = "登录接口",description = "根据账号密码检验登录")
    @ApiResponse(responseCode = "2000",description = "服务繁忙请稍后重试")
    @ApiResponse(responseCode = "3102",description = "用户不存在")
    @ApiResponse(responseCode = "3103",description = "用户名或密码错误")
    @ApiResponse(responseCode = "1000",description = "操作成功")
    @PostMapping("/login")
    public Result<String> login(@RequestBody LoginDTO loginDTO) {
        return sysUserService.login(loginDTO.getUserAccount(),loginDTO.getPassword());
    }

    // 退出登录
    @DeleteMapping("/logout")
    public Result<Void> logout(@RequestHeader(HttpConstants.AUTHENTICATION) String token) {
        return toResult(sysUserService.logout(token));
    }


    // 获取管理员昵称信息
    // 从 Header 中的 Authorization 中取出 token
    @RequestMapping("/info")
    public Result<LoginUserVO> info(@RequestHeader(HttpConstants.AUTHENTICATION) String token) {
        return sysUserService.info(token);
    }

    @Operation(summary = "新增管理员", description = "根据提供的信息新增管理员用户")
    @PostMapping("/add")
    @ApiResponse(responseCode = "1000", description = "操作成功")
    @ApiResponse(responseCode = "2000", description = "服务繁忙请稍后重试")
    @ApiResponse(responseCode = "3101", description = "用户已存在")
    public Result<Void> add(@RequestBody SysUserSaveDTO sysUserSaveDTO) {
        return toResult(sysUserService.add(sysUserSaveDTO));
    }

    @DeleteMapping("/{userId}")
    @Operation(summary = "删除用户", description = "根据path的userId来删除")
    @ApiResponse(responseCode = "1000", description = "成功删除用户")
    @ApiResponse(responseCode = "2000", description = "服务繁忙请稍后重试")
    @ApiResponse(responseCode = "3102", description = "用户不存在")
    public Result<Void> delete(@PathVariable Long userId) {
        return null;
    }

    @GetMapping("/detail")
    @Operation(summary = "获取用户详情", description = "根据查询条件查询用户详情")
    @ApiResponse(responseCode = "1000", description = "成功获取用户信息")
    @ApiResponse(responseCode = "2000", description = "服务繁忙请稍后重试")
    @ApiResponse(responseCode = "3102", description = "用户不存在")
    public Result<SysUserVO> detail(@RequestParam(required = true)Long userId,
                                    @RequestParam(required = false) String sex) {
        return null;
    }
}
